<!-- 我的体检 -->
<template>
	<view>
		<view class="tabs-wrapper">
			<liuyuno-tabs :tabData="tabsData" :defaultIndex="1" @tabClick='tabClick' />
		</view>
		<view class="list-wrapper" v-if="currentTabIndex == 0">
			<view class="item" v-for="(item, index) in listData1" :key="index" @click="goToTiJianOrderDetail(item, 1)">
				<p class="time">体检人【{{item.name}}】</p>
				<uni-tag class="float-right" :circle="true" :text="ifpay(item.ifpay)" :type="ifpayType(item.ifpay)" size="mini" />
				<div class="clearfix"></div>
				<p>家长姓名：{{item.parent_name}}</p>
				<p>家长电话：{{item.parent_phone}}</p>
			</view>
			<u-empty v-if="listData1.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/car.png">
			</u-empty>
		</view>
		<view class="list-wrapper" v-if="currentTabIndex == 1">
			<view class="item" v-for="(item, index) in listData2" :key="index" @click="goToTiJianOrderDetail(item, 2)">
				<p class="time">体检人【{{item.name}}】</p>
				<uni-tag class="float-right" :circle="true" :text="ifpay(item.ifpay)" :type="ifpayType(item.ifpay)" size="mini" />
				<div class="clearfix"></div>
				<p>工作单位：{{item.company}}</p>
				<p>身份证：{{item.idcard}}</p>
				<p>电话：{{item.phone}}</p>
			</view>
			<u-empty v-if="listData2.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/car.png">
			</u-empty>
		</view>
		<view class="list-wrapper" v-if="currentTabIndex == 2">
			<view class="item" v-for="(item, index) in listData3" :key="index" @click="goToTiJianOrderDetail(item, 3)">
				<p class="time">体检人【{{item.name}}】</p>
				<uni-tag class="float-right" :circle="true" :text="ifpay(item.ifpay)" :type="ifpayType(item.ifpay)" size="mini" />
				<div class="clearfix"></div>
				<p>工作单位：{{item.company}}</p>
				<p>身份证：{{item.idcard}}</p>
				<p>电话：{{item.phone}}</p>
			</view>
			<u-empty v-if="listData3.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/car.png">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import liuyunoTabs from "@/components/liuyuno-tabs/liuyuno-tabs.vue";
	export default {
		components: {
			liuyunoTabs
		},
		data() {
			return {
				tabsData: [{
						state: 1,
						name: '儿童入园体检'
					},
					{
						state: 2,
						name: '幼师体检'
					},
					{
						state: 3,
						name: '婚检'
					},
				],
				currentTabIndex: 0,
				openid: '',
				listData1: [],
				listData2: [],
				listData3: [],
			}
		},
		onLoad(option) {
			this.openid = uni.getStorageSync('openid')
			
		},
		onShow() {
			this.api_listinfo1()	
		},
		methods: {
			tabClick(val) {
				console.log(val)
				this.currentTabIndex = val
				if (val == 0) {
					this.api_listinfo1()
				}else if(val == 1) {
					this.api_listinfo2()
				}else if(val == 2) {
					this.api_listinfo3()
				}
			},
			
			goToTiJianOrderDetail(item, type) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/healthExamination/tijianOrderDetail?orderId=' + item.id + '&type=' + type,
					success: (res) => {
						// 通过eventChannel向被打开页面传送数据
						res.eventChannel.emit('detail', { data: item })
					}
				})
			},
			
			ifpay(val) {
				if (val == 0) {
					return '待支付'
				}else if (val == 1) {
					return '已支付'
				}else if (val == 2) {
					return '已核验'
				}else if (val == 7) {
					return '已退款'
				}
			},
			
			ifpayType(val) {
				if (val == 0) {
					return 'default'
				}else if (val == 1) {
					return 'default'
				}else if (val == 2) {
					return 'success'
				}
			},

			api_listinfo1() {
				this.$app._post_form2("entry/wxapp/apicheckup.listinfo1", {
					"openid": this.openid,
					"pageidx": "1",
					"pagesize": "1000"
				}, (res) => {
					console.log(res)
					this.listData1 = res
				})
			},
			api_listinfo2() {
				this.$app._post_form2("entry/wxapp/apicheckup.listinfo2", {
					"openid": this.openid,
					"pageidx": "1",
					"pagesize": "1000"
				}, (res) => {
					console.log(res)
					this.listData2 = res
				})
			},
			api_listinfo3() {
				this.$app._post_form2("entry/wxapp/apicheckup.listinfo3", {
					"openid": this.openid,
					"pageidx": "1",
					"pagesize": "1000"
				}, (res) => {
					console.log(res)
					this.listData3 = res
				})
			}
		}
	}
</script>

<style>
	>>>._item._active {
		color: #41C177 !important;
	}

	>>>._underline {
		background-color: #41C177 !important;
	}
</style>

<style scoped lang="scss">
	.tabs-wrapper {
		background-color: #fff;
	}

	.list-wrapper {
		padding: 10px;

		.item {
			padding: 10px;
			background-color: #fff;
			border-radius: 8px;
			color: #757575;
			font-size: .8rem;
			margin-bottom: 5px;

			p {
				line-height: 25px;
			}

			.time {
				color: #ff9800;
				float: left;
			}
		}
	}
</style>